package com.onlyphoto.onlymall.mvp.presenter

import com.onlyphoto.onlymall.base.BaseNetworkResponse

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CEditAddress
import com.onlyphoto.onlymall.mvp.model.MEditAddressImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.response.RegionBean2


class PEditAddressImpl(mContext: Context, mView: CEditAddress.IVEditAddress) : BasePresenter<CEditAddress.IVEditAddress, MEditAddressImpl>(mContext, mView, MEditAddressImpl()), CEditAddress.IPEditAddress {
    override fun getRegion(layout: Int) {
        mModel.requestRegion(layout, object : BaseObserver<RegionBean2>(mContext.get()) {
            override fun onSuccess(data: RegionBean2?, msg: String?) {
                mView.getRegionSuccess(data!!)
            }

            override fun onRequestStart() {
                mView.showLoading()
            }

            override fun onCodeError(t: BaseNetworkResponse<RegionBean2>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onFinally() {
                mView.hideLoading()
            }
        })
    }

    override fun addRegion() {
        val bean = mView.setAddressBean()
        mModel.addRegion(bean, object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.addRegionSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
                mView.showToast(t?.msg!!)
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun updateAddress() {
        val bean = mView.setAddressBean()
        mModel.updateAddress(bean, object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.updateAddressSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun deleteAddress() {
        val bean = mView.setDeleteAddressBean()
        mModel.deleteAddress(bean, object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.deleteAddressSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
